// import { defineStore } from 'pinia';
import { defineStore } from '../pinia';
import { computed, reactive, toRefs } from 'vue';

export const useStore = defineStore('main', {
  state() {
    return {
      count: 1,
      fruits:['苹果','香蕉'],
      obj:{
        a:1
      }
    }
  },
  getters: {
    doubleCount(c) {
      return this.count * 2
    }
  },
  actions: {
    // addCount(num) {
    //   this.count += num;
    //   return 111
    // },
    addCount(num) {
      return new Promise((resolve,reject)=>{
        setTimeout(() => {
          this.count += num;
          resolve(100);
        }, 1000);
      })
    },
  }
});

// 第二个参数可以是个setup自己想怎么写怎么写
// export const useStore = defineStore('main', () => {
//   const state = reactive({
//     count: 1
//   });
//   const doubleCount = computed(() => state.count * 2);
//   const addCount = (num) => {
//     state.count += num;
//   }
//   return { ...toRefs(state), doubleCount, addCount };
// });